package com.ly.honor.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.Country;
import com.ly.honor.service.CountryService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Country)表控制层
 *
 * @author makejava
 * @since 2022-11-16 11:53:59
 */
@RestController
@RequestMapping("country")
@Api(tags = "国家管理")
public class CountryController {
    /**
     * 服务对象
     */
    @Resource
    private CountryService countryService;

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @ApiOperation("查询所有国家信息")
    @GetMapping("selectCountryAll")
    public Result selectCountryAll() {
        return Result.ok(countryService.list());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getCountryById/{id}")
    public Result getCountryById(@PathVariable Integer id) {
        return Result.ok(this.countryService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param country 实体对象
     * @return 新增结果
     */
    @PostMapping("insertCountry")
    public Result insertCountry(@RequestBody Country country) {
        return Result.ok(this.countryService.save(country));
    }

    /**
     * 修改数据
     *
     * @param country 实体对象
     * @return 修改结果
     */
    @PostMapping("updateCountry")
    public Result updateCountry(@RequestBody Country country) {
        return Result.ok(this.countryService.updateById(country));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除结果
     */
    @DeleteMapping("deleteCountryById/{id}")
    public Result deleteCountryById(@PathVariable Integer id) {
        return Result.ok(this.countryService.removeById(id));
    }
}

